import re
import requests
from requests.api import head
ant_data=[]
headers={
    "User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.96 Safari/537.36 Edg/88.0.705.50"
}
f=open('home_data','r')
punctuation = '.!,;:?"“”\'、，；'
text = re.sub(r'[{}]+'.format(punctuation),' ',f.read())
init_data=text.split()
s_data=[]

for i in init_data:
    if i[-3:]=='ful':
        ant_data.append(i)
ant_data=list(set(ant_data))
print('ful词汇共有：'+str(len(ant_data)))

url='https://fanyi.baidu.com/v2transapi?from=en&to=zh'
adj_data=0
n_data=0
for i in ant_data:
    data={
        'kw':i
    }
    init_url='https://fanyi.baidu.com/sug'
    
    try:
        end_data=requests.post(url=init_url,data=data,headers=headers).json()
        if end_data['data'][0]['v'].split('.')[0]=='adj':
            adj_data=adj_data+1
            print(end_data['data'][0]['v'])
        if end_data['data'][0]['v'].split('.')[0]=='n':
            print(end_data['data'][0]['v'])
            n_data+=1
    except Exception as e:
        print(i+"查询失败")
print('adj:'+str(adj_data))
print('n:'+str(n_data))